package com.shop2cn.iapi.couponmanage.testcase.old;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.couponmanage.parameter.CreateBagBean;
import com.shop2cn.iapi.couponmanage.parameter.CreateBean;
import com.shop2cn.iapi.couponmanage.parameter.CreateCouponBean;
import com.shop2cn.iapi.couponmanage.parameter.GetGenerateStatusBean;
import com.shop2cn.iapi.couponmanage.service.CreateBagCall;
import com.shop2cn.iapi.couponmanage.service.CreateCouponCall;
import com.shop2cn.iapi.couponmanage.service.GetGenerateStatusCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponShop2cnMCallService;
import com.ymttest.database.model.couponconversion;
import com.ymttest.database.model.couponsendtask;
import com.ymttest.database.sqlwapper.couponconversionWapper;
import com.ymttest.database.sqlwapper.couponsendtaskWapper;
//import com.ymttest.database.model.couponconversion;
//import com.ymttest.database.model.YmtCouponGenerateTask;
//import com.ymttest.database.sqlwapper.couponconversionWapper;
//import com.ymttest.database.sqlwapper.YmtCouponGenerateTaskWapper;
/**
*获取兑换码生成状态
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetGenerateStatus{
	private static GetGenerateStatusBean getgeneratestatusBean;
	private static GetGenerateStatusCall getgeneratestatusCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取兑换码生成状态");
	}

	@Before
	public void caseUp() {
		getgeneratestatusBean=new GetGenerateStatusBean();
		getgeneratestatusCall=new GetGenerateStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getgeneratestatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetGenerateStatus_001() {
		Logger.start(true,"获取兑换码生成状态");
		try {
			couponconversion bill = new couponconversionWapper().getTop1RandomBill();
			
			getgeneratestatusBean.setConversionBillId(bill.getConversionId());
			getgeneratestatusCall.setData(getgeneratestatusBean);
			getgeneratestatusCall.callService();			
			
			Logger.verifyEquals("0", getgeneratestatusCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getgeneratestatusCall.getMessage(), "验证返回Message");

			String status = getgeneratestatusCall.getGenerateStatus();
			couponsendtask task = new couponsendtaskWapper().selectByCouponBatchCode(bill.getConversionId().toString()).get(0);
			Logger.verifyEquals(task.getStatus().intValue(), Integer.parseInt(status), "验证返回status");
	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetGenerateStatus_004() {
		Logger.start(true,"获取兑换码生成状态-随机");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createCouponBean.setAcquireCouponMethod(2);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			List<String> batchCodes= new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());
			CreateBean CreateBean=couponCallService.setDefaultRandomCreateBean(batchCodes);
			couponCallService.create(CreateBean);
			
			couponconversion bill = new couponconversionWapper().getTop1();
			getgeneratestatusBean.setConversionBillId(bill.getConversionId());
			getgeneratestatusCall.setData(getgeneratestatusBean);
			getgeneratestatusCall.callService();			
			
			Logger.verifyEquals("0", getgeneratestatusCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getgeneratestatusCall.getMessage(), "验证返回Message");

			String status = getgeneratestatusCall.getGenerateStatus();
			couponsendtask task = new couponsendtaskWapper().selectByCouponBatchCode(bill.getConversionId().toString()).get(0);
			Logger.verifyEquals(task.getStatus().intValue(), Integer.parseInt(status), "验证返回status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_GetGenerateStatus_005() {
		Logger.start(true,"获取兑换码生成状态-自定义(自定义不用生成短码，不做验证)");
		try {
			CouponShop2cnMCallService couponCallService = new CouponShop2cnMCallService();
			CreateCouponBean createCouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createCouponBean.setAcquireCouponMethod(2);
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createCouponBean);
			List<String> batchCodes= new ArrayList<>();
			batchCodes.add(createCouponCall.getBatchCode());
			CreateBean CreateBean=couponCallService.setDefaultCustomCreateBean(batchCodes);
			couponCallService.create(CreateBean);
			
			couponconversion bill = new couponconversionWapper().getTop1();
			getgeneratestatusBean.setConversionBillId(bill.getConversionId());
			getgeneratestatusCall.setData(getgeneratestatusBean);
			getgeneratestatusCall.callService();			
			
			Logger.verifyEquals("0", getgeneratestatusCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getgeneratestatusCall.getMessage(), "验证返回Message");

			String status = getgeneratestatusCall.getGenerateStatus();
			couponsendtask task = new couponsendtaskWapper().selectByCouponBatchCode(bill.getConversionId().toString()).get(0);
			Logger.verifyEquals(task.getStatus().intValue(), Integer.parseInt(status), "验证返回status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetGenerateStatus_002() {
		Logger.start(true,"获取兑换码生成状态-ConversionBillId空");
		try {
			
			getgeneratestatusCall.setData(getgeneratestatusBean);
			getgeneratestatusCall.callService();			
			
//			Logger.verifyEquals("2", getgeneratestatusCall.getCode(), "验证返回code");
			Logger.verifyIsContains("未查询到兑换码生成的任务数据", getgeneratestatusCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetGenerateStatus_003() {
		Logger.start(true,"获取兑换码生成状态-ConversionBillId不存在");
		try {
			getgeneratestatusBean.setConversionBillId(9999);
			
			getgeneratestatusCall.setData(getgeneratestatusBean);
			getgeneratestatusCall.callService();			
			
//			Logger.verifyEquals("2", getgeneratestatusCall.getCode(), "验证返回code");
			Logger.verifyIsContains("未查询到兑换码生成的任务数据", getgeneratestatusCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}